//var app_url = 'http://192.168.1.38/CoCMobile/public/index.php';
var app_url = 'http://192.168.1.234/CoCMobile/public/index.php'; //杨
//var app_url = 'https://www.cdzjkl.com/index.php'; 
//var app_url = 'https://test.cdzjkl.com/index.php';
function quchong(attay) {
    var a = [];
    var b = {};
    mui.each(attay, function(index, val) {
        if(!b[val]) {
            a.push(val);
            b[val] = 1;
        }
    })
    return a;
}
/*
 * 检查网络
 * */
function checkNet(backfn) {
    //检查网络
    var network = plus.networkinfo.getCurrentType();
    if(network == 1) {
        //      btnArray = ["设置", "取消"];
        //      mui.confirm('网络异常，是否前往设置？', '网络连接异常', btnArray, function(e) {
        //          if(e.index == 0) {
        //              if(plus.os.name == "Android") {
        //                  var main = plus.android.runtimeMainActivity();
        //                  var Intent = plus.android.importClass("android.content.Intent");
        //                  var mIntent = new Intent('android.settings.SETTINGS');
        //                  main.startActivity(mIntent);
        //              } else {
        //                  plus.runtime.launchApplication({
        //                      action: 'prefs:root=MOBILE_DATA_SETTINGS_ID'
        //                  }, function(e) {}); //WIFI
        //              }
        //          } else {
        //              if(plus.os.name == "Android") {
        ////                  plus.runtime.quit();
        //              } else {
        ////                  mui.toast("此平台不支持直接退出程序，请按Home键切换应用");
        //              }
        //          }
        //      })
        mui.toast('您网络连接异常');
    } else if(this.network == 3 || network > 3) {
        global_ajax_fn('/index/login/index', {
            cellphone: localStorage.cellphone
        }, '网络登录', backfn)
        mui.toast('您网络已切换到移动流量');
    } else {
        mui.toast('您网络已切换到WIFI');
        global_ajax_fn('/index/login/index', {
            cellphone: localStorage.cellphone
        }, '网络登录', backfn)
    }
    this.network = network;
}

//打开键盘
var nativeWebview, imm, InputMethodManager;
var initNativeObjects = function() {
    if(mui.os.android) {
        var main = plus.android.runtimeMainActivity();
        var Context = plus.android.importClass("android.content.Context");
        InputMethodManager = plus.android.importClass("android.view.inputmethod.InputMethodManager");
        imm = main.getSystemService(Context.INPUT_METHOD_SERVICE);
    } else {
        nativeWebview = plus.webview.currentWebview().nativeInstanceObject();
    }
};
var showSoftInput = function() {
    if(mui.os.android) {
        imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
    } else {
        nativeWebview.plusCallMethod({
            "setKeyboardDisplayRequiresUserAction": false
        });
    }
    setTimeout(function() {
        //此处可写具体逻辑设置获取焦点的input
        var inputElem = document.querySelector('input');
        inputElem.focus();
        inputElem.style.textAlign = 'left'
    }, 200);
};

//分享数据
/*json_data:新建时的传输数据
shares：获取分享权限对象
url：分享的页面路径
name_t：分享类型
分享内容名称
callbackFn:回调函数*/
function shares_fn(json_data, shares, url, name_t, callbackFn) {
    var ids = [{
                id: "weixin",
                ex: "WXSceneSession"
            }, {
                id: "weixin",
                ex: "WXSceneTimeline"
            }
            //                      {
            //                          id: "sinaweibo"
            //                      }, {
            //                          id: "tencentweibo"
            //                      }, {
            //                          id: "qq"
            //                      }
        ],
        bts = [{
                title: "分享给微信好友"
            }, {
                title: "分享到微信朋友圈"
            }
            //                      {
            //                          title: "分享到新浪微博"
            //                      }, {
            //                          title: "分享到腾讯微博"
            //                      }, {
            //                          title: "分享到QQ"
            //                      }
        ];
    plus.nativeUI.actionSheet({
        cancel: "取消",
        buttons: bts
    }, function(e) {
        var i = e.index;
        if(i > 0) {
            var s_id = ids[i - 1].id;
            var share = shares[s_id];
            if(share) {
                if(!share.authenticated) {
                    if(name_t == 'CoC邀请') {
                        shareMessage(share, ids[i - 1].ex, url, name_t);
                        return;
                    } else if(name_t == '分享APP') {
                        share_app_fn(share, ids[i - 1].ex)
                        //                  	my_confirm('提示','确认分享',['取消','确定'],function(e){
                        //							if (e == 1) {
                        //								share_app_fn(share,ids[i - 1].ex)
                        //							}
                        //						})
                    } else {
                        mui.confirm('确认分享？', '提示', ['确认', '取消'], function(e) {
                            if(e.index == 0) {
                                share_newCoc_fn(json_data, share, ids[i - 1].ex, url, name_t, callbackFn)
                            }
                        })
                    }
                } else {
                    share.authorize(function() {
                        if(name_t == 'CoC邀请') {
                            shareMessage(share, ids[i - 1].ex, url, name_t);
                            return
                        } else if(name_t == '分享APP') {
                            share_app_fn(share, ids[i - 1].ex)
                            //	                    	my_confirm('提示','确认分享',['取消','确定'],function(e){
                            //								if (e == 1) {
                            //									share_app_fn(share,ids[i - 1].ex)
                            //								}
                            //							})
                        } else {
                            mui.confirm('确认分享？', '提示', ['确认', '取消'], function(e) {
                                if(e.index == 0) {
                                    share_newCoc_fn(json_data, share, ids[i - 1].ex, url, name_t, callbackFn)
                                }
                            })
                        }
                    }, function(e) {
                        console.log("认证授权失败：" + e.code + " - " + e.message);
                    });
                }
            } else {
                mui.toast("无法获取分享服务，请检查manifest.json中分享插件参数配置，并重新打包")
            }
        }
    });
}

//获取分享权限
function shareMessage(share, ex, key_num, name_t, callbackFn) {
    callbackFn()
    var msg = {
        extra: {
            scene: ex
        }
    };
    msg.href = 'https://www.cdzjkl.com' + '/share?id=' + key_num.coc_key + '&types=coc';
    msg.title = name_t;
    msg.content = key_num.creator.fname + '邀请你进去CoC讨论，房间钥匙号：' + key_num.coc_key;
    if(~share.id.indexOf('weibo')) {
        msg.content += "；体验地址：" + 'https://www.cdzjkl.com' + '/share?id=' + key_num.coc_key + '&types=coc';
    }
    msg.thumbs = ['https://www.cdzjkl.com' + "/downloads/200.png"];
    share.send(msg, function() {
        mui.alert("恭喜您，发送成功", 'CoC建助通')
        //  	mui.back();
    }, function(e) {
        mui.alert("发送失败~请稍候重试", 'CoC建助通')
        //  	mui.back();
    });
}

function shareMessage_2(share, ex, share_title, share_content, share_url, share_pic) {
    var msg = {
        extra: {
            scene: ex
        }
    };
    msg.href = share_url;
    msg.title = share_title;
    msg.content = share_content;
    if(~share.id.indexOf('weibo')) {
        msg.content += "；体验地址：" + share_url;
    }
    msg.thumbs = share_pic;
    share.send(msg, function() {
        mui.alert("分享到\"" + share.description + "\"成功！ ", 'CoC建助通')
    }, function(e) {
        mui.alert("分享到\"" + share.description + "\"失败啦！ ", 'CoC建助通')
        //  	alert("分享到\"" + share.description + "\"失败: " + e.code + " - " + e.message)
    });
}
//分享APP
function share_app_fn(share, ex) {
    mui.ajax(app_url + '/index/Share/shareParameters', {
        data: {
            log_msg: localStorage.globlAjaxData
        },
        dataType: 'json', //服务器返回json格式数据
        type: 'post', //HTTP请求类型
        timeout: 10000, //超时时间设置为10秒
        success: function(data) {
            if(data.status = 'success') {
                var data_back = data.result;
                var share_title = data_back.title;
                var share_content = data_back.content;
                var share_url = data_back.share_url;
                var share_pic = data_back.share_pic;
                shareMessage_2(share, ex, share_title, share_content, share_url, share_pic);
            } else {
                mui.toast("服务器打怪兽去啦~请您稍等片刻");
            }
        },
        error: function(xhr, type, errorThrown) {
            //异常处理；
            alert('分享失败')
        }
    })
}
//分享成功新建coc
function share_newCoc_fn(json_data, share, ex, url, name_t, callbackFn) {
    plus.nativeUI.showWaiting();
    json_data.log_msg = localStorage.globlAjaxData;
    mui.ajax(app_url + '/index/coc/buildDiscuss', {
        data: json_data,
        dataType: 'json', //服务器返回json格式数据
        type: 'post', //HTTP请求类型
        timeout: 10000, //超时时间设置为10秒
        success: function(data) {
            plus.nativeUI.closeWaiting();
            console.log('CoC' + JSON.stringify(data))
            if(data.status == 'failed') {
                mui.toast(data.message);
            }
            if(data.status == 'success') {
                var key_num = data.coc_key;
                //shareMessage(share, ex, key_num, name_t);
                shareMessage(share, ex, data, name_t, callbackFn);
            }
            if(data.status == 'notice') {
                mui.confirm('分享已存在!是否进入CoC?', '提示', ['确认', '取消'], function(e) {
                    if(e.index == 0) {
                        var extras = {
                            news_id: data.id
                        }
                        if(json_data.types == 'achi') {
                            openWebview_fn('../../../view/coc/coc_debateInfo/debate_index.html', '../../view/coc/coc_debateInfo/debate_index.html', extras)
                        } else {
                            openWebview_fn('../../view/coc/coc_debateInfo/debate_index.html', '../../view/coc/coc_debateInfo/debate_index.html', extras)
                        }
                    }
                })

            }
        },
        error: function(xhr, type, errorThrown) {
            plus.nativeUI.closeWaiting();
            //异常处理；
            alert('分享失败')
        }
    });
}
//打开新页面
var openWebview_fn = function(route, onlyId, extra) {
    mui.openWindow({
        url: route,
        id: onlyId,
        extras: extra,
        show: {
            //          aniShow:'pop-in',
            duration: 200
        },
        waiting: {
            autoShow: false
        }
    })
}

function open_window(url, id, extras) {
    mui.openWindow({
        url: url,
        id: id,
        extras: extras,
        waiting: {
            autoShow: false
        },
        show: {
            aniShow: 'pop-in',
            duration: 300
        }
    })
}
//消息未读数
function message_unread_fn(unread_logo, num) {
    mui.ajax(app_url + "/index/message/newMessageCount", {
        data: {
            log_msg: localStorage.globlAjaxData,
            token: localStorage.token,
            id: localStorage.user_id
        },
        dataType: 'json', //服务器返回json格式数据 
        type: 'post', //HTTP请求类型 
        timeout: 10000, //超时时间设置为10秒 
        success: function(data) {
            if(data.status == 'failed') {
                unread_logo.style.display = 'none';
            } else if(data.status == 'success') {
                if(data.count > 0) {
                    unread_logo.style.display = 'block';
                } else {
                    unread_logo.style.display = 'none';
                }
            }
        },
        error: function(xhr, type, errorThrown) {
            //异常处理；
            mui.toast(errorThrown);
        }
    });
}
//消息盒子跳转函数
function message_fn(el, url, id, webview) { //el:消息入口按钮;url:消息列表地址;id:消息列表页面id;webview:当前页面id,方便区分消息列表返回页面
    el.addEventListener('tap', function() {
        mui.openWindow({
            url: url,
            id: id,
            extras: {
                pre_view: webview
            },
            waiting: {
                autoShow: false
            }
        })
    })
}
//消息列表返回：主要涉及四个页面
function message_back_fn(parentPage) { //parentPage:返回页面ID，对应上一个跳转函数的webview
    //改写返回操作
    mui.plusReady(function() {
        var old_back = mui.back;
        mui.back = function() {
            var vNextPage = null;
            //获得下一个页面
            if(vNextPage == null) {
                vNextPage = plus.webview.getWebviewById(parentPage); //这个是下一个页面的ID，第一次，他肯定为空，所以，这里面这个fire方法，是不会执行的。
                if(vNextPage != null) {
                    //触发下一个页面的自定义事件
                    mui.fire(vNextPage, 'Message_DATA', {});
                }
            }
            var vCurrentWebView = plus.webview.currentWebview();
            if(vCurrentWebView != null) {
                //				vCurrentWebView.hide('none');
            }
            old_back();
        }
    });
}
//弹框
var quren_mask;

function my_confirm(title_text, content_text, btns, callback) {
    quren_mask = mui.createMask();
    quren_mask.show()
    /*高*/
    var w_h = window.innerHeight;
    var d_h = Math.floor(w_h / 4.5);
    /*宽*/
    var w_w = window.innerWidth;
    var d_w = Math.floor(w_w / 1.25);
    /*上*/
    var d_t = (w_h - d_h) / 2;
    /*左*/
    var d_f = (w_w - d_w) / 2;
    /*外层div*/
    var div = document.createElement('div');
    div.setAttribute('id', 'aa')
    div.style.cssText = 'padding:0 10px 10px 10px;border-radius:2%;position: fixed;top:' + d_t + 'px;left:' + d_f + 'px;background: #fff;width: ' + d_w + 'px;'

    /*标题*/
    var title = document.createElement('h4');
    title.style.cssText = 'margin: 0;font-weight: 200;text-align: center;line-height: 40px;color: #444;border-bottom:1px solid #e6e6e6 ;'
    title.innerText = title_text;
    /*内容*/
    var content = document.createElement('p');
    content.innerText = content_text;
    content.style.cssText = 'margin:0;padding: 10px;font-family: 微软雅黑;text-align: left;line-height: 35px;color: #444;'
    /*按钮*/
    var buts = document.createElement('div');
    buts.style.cssText = 'padding-top: 10px;'
    buts.className = 'flex_row';
    buts.innerHTML = '<span id="span_a" class="flex_1" style="text-align:center;border-radius:3px;font-size:18px;margin:0 15px 0 0;line-height:40px;border:1px solid #0099ff;color:#0099ff;background:#fff">' + btns[0] + '</span>' +
        '<span id="span_b" class="flex_1" style="text-align:center;;border-radius:3px;font-size:18px;margin:0;line-height:40px;color:#fff;background:#0099ff">' + btns[1] + '</span>'
    div.appendChild(title);
    div.appendChild(content);
    div.appendChild(buts);
    quren_mask[0].appendChild(div);
    click_btn_fn(callback)
}

function click_btn_fn(callback) {
    document.getElementById('span_a').addEventListener('tap', function() {
        callback(0)
    });
    document.getElementById('span_b').addEventListener('tap', function() {
        callback(1)
    })
}
(function(doc, win) {
    var docEl = doc.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function() {
            var clientWidth = docEl.clientWidth;
            if(!clientWidth) return;
            docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
        };

    if(!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);
//localStorage.abc = 1;
//setInterval(function(){
// if(localStorage.abc==1){
//     console.log(localStorage.abc)
// };
// localStorage.abc++;
// setTimeout(function(){
//     localStorage.abc =1;
//     console.log(localStorage.abc)
// },1000)
//},10000);

var only_again_Login = 0;
/*重新登录*/
function again_Login(mess, fn) {
    if(mess && mess.indexOf('token') > -1) {
        if(only_again_Login == 0) {
            mui.confirm('您的账号在另一台手机登录。如非本人操作,建议重新登录。', '下线通知', ['退出', '重新登录'], function(e) {
                if(e.index == 1) {
                    var mask = mui.createMask();
                    mask.show()
                    var divobj = document.createElement('div');
                    divobj.setAttribute('id', 'again_login_div');
                    divobj.style.cssText = 'position: fixed;top: 0;bottom: 0;width: 100%;background:rgba(0,0,0,0.3)';
                    divobj.innerHTML = '<div class="phone_position_center" style="display:block">' +
                        '<p style="color:#000000">手机验证</p>' +
                        '<input type="number" id = "again_phone_input" placeholder="请输入手机号"/>' +
                        '<div class="flex_row">' +
                        '<input type="number" id = "again_yzm_input" style="margin-right: 0.1rem;" class="flex_1" placeholder="请输入验证码"/>' +
                        '<input class="phone_btnE6" type="button" disabled="disabled" id = "again_yzmBtn"  value="点击获取"/>' +
                        '</div>' +
                        '<input type="button" style="font-size: 0.32rem;width: 100%;margin-top: 0.3rem;" class="phone_btnE6" disabled="disabled" id = "again_okBtn" name=""  value="验证"/>' +
                        '</div>';
                    mask[0].appendChild(divobj);
                    //防止事件冒泡
                    divobj.addEventListener('tap', function(e) {
                        e.stopPropagation();
                    })
                    //添加事件
                    add_listener(fn);
                    only_again_Login = 0;
                } else {
                    if(plus.os.name == "Android") { //判断设备
                        plus.runtime.quit(); //退出系统
                        localStorage.cellphone = '';
                    } else {
                        localStorage.cellphone = '';
                        var login = plus.webview.create('../login/login.html', '../login/login.html');
                        login.addEventListener('loaded', function() {
                            login.show('none', 200, function() {
                                var web_all = plus.webview.all();
                                var app_web = plus.webview.getLaunchWebview();
                                mui.later(function() {
                                    mui.each(web_all, function(i, v) {
                                        if(v.id != app_web.id && v.id != '../login/login.html') {
                                            v.close('none');
                                        }
                                    })
                                }, 500)
                            })
                        })
                    }
                }
            })
        }
    }
    only_again_Login++;
}

//添加重新登录验证事件
function add_listener(callback_fn) {
    //手机号数据监听
    document.getElementById('again_phone_input').addEventListener('input', function() {
        if(this.value.length == 11) {
            mui('#again_yzmBtn')[0].className = 'phone_btn45a';
            mui('#again_yzmBtn')[0].removeAttribute('disabled')
        } else {
            mui('#again_yzmBtn')[0].className = 'phone_btnE6';
            mui('#again_yzmBtn')[0].setAttribute('disabled', 'disabled')
        }
    });
    //验证码input
    document.getElementById('again_yzm_input').addEventListener('input', function() {
        var phone = mui('#again_phone_input')[0].value;
        if(phone.length == 11 && this.value.length == 4) {
            mui('#again_okBtn')[0].className = 'phone_btn45a';
            mui('#again_okBtn')[0].removeAttribute('disabled')
        } else {
            mui('#again_okBtn')[0].className = 'phone_btnE6';
            mui('#again_okBtn')[0].setAttribute('disabled', 'disabled')
        }
    });
    //获取验证码按钮
    var nums = 60;
    document.getElementById('again_yzmBtn').addEventListener('tap', function() {
        var datas = {
            cellphone: mui('#again_phone_input')[0].value
        }
        this.value = nums + 's';
        countdown_fn();
        this.className = 'phone_btnE6';
        this.setAttribute('disabled', 'disabled')
        global_ajax_fn('/index/login/sendText', datas, '获取验证码')
    });
    //验证登录
    document.getElementById('again_okBtn').addEventListener('tap', function() {
        var datas = {
            cellphone: mui('#again_phone_input')[0].value,
            code: mui('#again_yzm_input')[0].value,
            type: 1
        }
        clearInterval(intertime);
        global_ajax_fn('/index/login/index', datas, '验证登录', callback_fn)
    });

    //倒计时
    var intertime;

    function countdown_fn() {
        intertime = setInterval(function() {
            if(nums != 0) {
                mui('#again_yzmBtn')[0].value = nums + 's';
                nums--;
            } else {
                mui('#again_yzmBtn')[0].className = 'phone_btn45a';
                mui('#again_yzmBtn')[0].removeAttribute('disabled')
                mui('#again_yzmBtn')[0].value = '点击获取';
                clearInterval(intertime);
                nums = 60;
            }
        }, 1000)
    }
}

//统一登录事件请求
function global_ajax_fn(urls, datas, types, callback_fn) {
    datas.log_msg = localStorage.globlAjaxData;
    mui.ajax(app_url + urls, {
        data: datas,
        dataType: 'json',
        type: 'post',
        timeout: 10000,
        success: function(data) {
            if(data.status == 'failed') {
                if(types == '获取验证码') {
                    mui.toast(data.message);
                } else if(types == '验证登录') {
                    console.log('验证失败');
                }
            }
            if(data.status == 'success') {
                if(types == '获取验证码') {

                } else {
                    if(types == '验证登录') {
                        mui.toast('登录成功');
                        var self = document.getElementById('again_login_div');
                        self.parentNode.removeChild(self);
                    }
                    localStorage.token = data['result']['token']; //存储token值
                    localStorage.user_id = data['result']['userinfo']['userid']; //存储用户id
                    localStorage.company = data['result']['userinfo']['company']; //存储公司id
                    localStorage.user_name = data['result']['userinfo']['name']; //存储人员名称
                    localStorage.qx_id = data['result']['userinfo']['qx_id'];
                    localStorage.cellphone = data['result']['userinfo']['cellphone'];
                    localStorage.is_wechat = data['result']['userinfo']['is_wechat'];
                    callback_fn()
                }
            }
        },
        error: function(data) {
            console.log('失败')
        }
    })
}

function chongxin_other_login_fn(name, other_id, other_img, other_sex, fn) {
    mui.ajax(app_url + '/index/login/wechatRegister', {
        data: {
            name: name,
            unionid: other_id,
            avatar: other_img,
            sex: other_sex,
            log_msg: localStorage.globlAjaxData
        },
        dataType: 'json',
        type: 'post',
        timeout: 20000,
        success: function(back) {
            if(back.status == 'failed') {
                mui.toast(back.message);
            } else if(back.status == 'success') {

                var data = back.result;
                localStorage.token = data['token']; //存储token值
                localStorage.user_id = data['userid']; //存储用户id
                localStorage.user_name = data['name']; //存储人员名称；
                localStorage.other_type = data['is_wechat'] //微信登录区别；
                localStorage.qx_id = data['qx_id']; //权限
                localStorage.cellphone = data['cellphone'];
                fn(); //执行回调
                //                          mui.openWindow({
                //                             url:"../index.html",
                //                              id:'zong_index',
                //                              show:{
                //                                 aniShow:'fade-in'
                //                              },
                //                              waiting:{
                //                                   autoShow:false
                //                              }
                //                          })
                //                          mui.later(function(){
                //                              plus.nativeUI.closeWaiting()
                //                          })
            }
        },
        error: function(xhr, type, errorThrown) {
            //异常处理；
            plus.nativeUI.closeWaiting();
            mui.toast('网络开小差！');
            mui.toast(errorThrown);
        }
    })
}

function again_other_login_fn(name, other_id, other_img, other_sex) {
    mui.ajax(app_url + '/index/login/wechatRegister', {
        data: {
            name: name,
            unionid: other_id,
            avatar: other_img,
            sex: other_sex,
            log_msg: localStorage.globlAjaxData
        },
        dataType: 'json',
        type: 'post',
        timeout: 20000,
        success: function(back) {
            if(back.status == 'failed') {
                //mui.toast(back.message);
            } else if(back.status == 'success') {
                var data = back.result;
                localStorage.token = data['token']; //存储token值
                localStorage.user_id = data['userid']; //存储用户id
                localStorage.user_name = data['name']; //存储人员名称；
                localStorage.other_type = data['is_wechat'] //微信登录区别；
                localStorage.qx_id = data['qx_id']; //权限
            }
        },
        error: function(xhr, type, errorThrown) {
            mui.toast('登录失败');
        }
    })
}

function shares_new(shares, name, key) {
    var ids = [{
        id: "weixin",
        ex: "WXSceneSession"
    }, {
        id: "weixin",
        ex: "WXSceneTimeline"
    }];
    var bts = [{
        title: "分享给微信好友"
    }, {
        title: "分享到微信朋友圈"
    }];
    plus.nativeUI.actionSheet({
        cancel: "取消",
        buttons: bts
    }, function(e) {
        var i = e.index;
        if(i > 0) {
            var s_id = ids[i - 1].id; //选中的是哪个分享
            var share = shares[s_id];
            if(share) {
                if(share.authenticated) {
                    var msg = {
                        extra: {
                            scene: ids[i - 1].ex //分享到微信好友还是朋友圈
                        }
                    };
                    //                  msg.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=io.dcloud.H55C317CA';
                    msg.href = 'https://www.cdzjkl.com' + '/share?id=' + key + '&types=coc';
                    msg.title = '建筑行业通';
                    msg.content = name + ' 邀请你进去CoC讨论，房间钥匙号：' + key;
                    if(~share.id.indexOf('weibo')) {
                        //                      msg.content += "；体验地址：" + 'http://a.app.qq.com/o/simple.jsp?pkgname=io.dcloud.H55C317CA';
                        msg.content += "；体验地址：" + 'https://www.cdzjkl.com' + '/share?id=' + key + '&types=coc';
                    }
                    msg.thumbs = ['https://www.cdzjkl.com' + "/downloads/200.png"];
                    share.send(msg, function() {
                        mui.back();
                        console.log("分享到\"" + share.description + "\"成功！ ");
                    }, function(e) {
                        console.log("分享到\"" + share.description + "\"失败: " + e.code + " - " + e.message);
                    });
                }
            }
        }
    })
}

//获取权限id
/*fn:回调函数*/
function get_Qxid(fn) {
    mui.ajax(app_url + '/index/Mine/basicInfo', {
        data: {
            log_msg: localStorage.globlAjaxData,
            token: localStorage.token,
            id: localStorage.user_id,
        },
        dataType: 'json', //服务器返回json格式数据
        type: 'post', //HTTP请求类型
        timeout: 20000, //超时时间设置为10秒
        success: function(back) {
            //服务器返回响应，根据响应结果，分析是否登录成功；
            if(back.status == 'failed') {
                again_Login(back.message, function() {
                    window.location.reload()
                })
            } else if(back.status == 'success') {
                localStorage.qx_id = back.result.qx_id;
                fn();
            }
        },
        error: function(xhr, type, errorThrown) {

        }
    });
}

//选择时间
/*div:选择时间储存的值,mindate默认小时间，nowdate默认选中时间*/
function select_time(div, mindate, nowdate) {
    var dDate = new Date();
    var minDate = new Date();
    var maxDate = new Date();
    if(mindate) {
        var minY = mindate[0],
            minM = mindate[1],
            minD = mindate[2];
        minDate.setFullYear(minY, minM, minD);
    } else {
        minDate.setFullYear(2000, 0, 1);
    }
    if(nowdate) {
        var nowY = nowdate[0],
            nowM = nowdate[1],
            nowD = nowdate[2];
        dDate.setFullYear(nowY, nowM, nowD)
    }
    plus.nativeUI.pickDate(function(e) {
        var d = e.date;
        var yue = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1);
        var ri = d.getDate() < 10 ? '0' + d.getDate() : d.getDate();
        div.innerText = d.getFullYear() + "-" + yue + "-" + ri;
    }, function(e) {

    }, {
        date: dDate,
        minDate: minDate
        //      maxDate: minDate
    });
}

//下拉加载
var drop_down = function(datas, callfn) { //下拉刷新
    var obj = document.getElementById(datas.setElement);
    var body = obj.parentNode;
    var vars = {
        ismove: false, //是否存在下拉刷新
        isajax: false, //是否在请求
        setStyle: function(time, move) {
            return ';transition:all ' + time + 's;-webkit-transition:all ' + time + 's;transform: translate(0,' + move + 'px);'
        }
    };
    //回调需要的事件
    var fn = {
        success: function(backfn) {
            setTimeout(function() {
                backfn() //回调函数
                vars.isajax = false;
                obj.style.cssText += vars.setStyle(0.3, '-' + datas.setminH);
            }, 2000)
        }
    }

    obj.addEventListener('touchstart', function(e) { //开始触屏
        var e = e ? e : event;
        if(body.scrollTop == 0 && !vars.isajax) {
            vars.startY = e.touches[0].clientY;
            //                      obj.style.cssText += vars.setStyle(0,0);
            datas.startfn();
        }

    })
    obj.addEventListener('touchmove', function(e) { //开始移动
        var e = e ? e : event;
        vars.moveY = e.touches[0].clientY;
        if(body.scrollTop <= 0 && !vars.isajax) { //当父级的滚动高度为0且没有请求执行
            if(vars.moveY > vars.startY && vars.startY != 0) { //当向下滑才执行
                datas.movefn({
                    startY: vars.startY,
                    moveY: vars.moveY
                });
                vars.moveH = vars.moveY - vars.startY;
                obj.style.cssText += vars.setStyle(0, vars.moveH / 2 - datas.setminH)
                e.preventDefault(); //在下拉刷新的过程中阻止浏览器的默认行为
                vars.ismove = true;
                if(vars.moveH / 2 > datas.setminH) {
                    datas.moveMinfn();
                } else {
                    datas.startfn();
                }
            }
        };
    })
    obj.addEventListener('touchend', function(e) { //离开屏幕
        if(vars.ismove && !vars.isajax) {
            console.log(vars.moveY - vars.startY + ',' + datas.setminH)
            if((vars.moveY - vars.startY) / 2 > datas.setminH) { //下拉的够下
                obj.style.cssText += vars.setStyle(0.6, 0);
                vars.isajax = true; //下拉大于高度请求
                datas.endfn();
                callfn(fn)
            } else {
                obj.style.cssText += vars.setStyle(0.3, '-' + datas.setminH);
            }
            vars.ismove = false;
        }
        vars.startY = 0; //离开屏幕重新设置起始值
    })
}

//简单分享
function simple_share(url,title,content) {
    var shares = {};
    plus.share.getServices(function(s) {
        if(s && s.length > 0) {
            mui.each(s, function(i, v) {
                var t = s[i];
                shares[t.id] = t;
            })
        }
    }, function() {
        console.log("获取分享服务列表失败");
    });
    var ids = [{
        id: "weixin",
        ex: "WXSceneSession"
    }, {
        id: "weixin",
        ex: "WXSceneTimeline"
    }];
    var bts = [{
        title: "分享给微信好友"
    }, {
        title: "分享到微信朋友圈"
    }];
    plus.nativeUI.actionSheet({
        cancel: "取消",
        buttons: bts
    }, function(e) {
        var i = e.index;
        if(i > 0) {
            var s_id = ids[i - 1].id;
            var share = shares[s_id];
            if(share) {
                if(share.authenticated) { //是否授权分享
                    share.authorize(function() { //验证
                        //分享内容
                        var msg = {
                            extra: {
                                scene: ids[i - 1].ex
                            }
                        };
                        msg.href = url;
                        msg.title = title;
                        msg.content = content;
                        if(~share.id.indexOf('weibo')) {
                            msg.content += "；体验地址：" + url
                        }
                        msg.thumbs = ['https://www.cdzjkl.com' + "/downloads/200.png"];
                        share.send(msg, function() {
                            mui.toast("分享成功")
                        }, function(e) {
                            mui.toast("分享失败")
                        });
                    }, function() {
                        mui.toast('认证失败')
                    })
                }
            }
        }
    })
}